// Copyright 2012 wstc

#include "base/bitmap.h"
#include <gtest/gtest.h>

class BitmapTest: public ::testing::Test {
  public:
    BitmapTest() {
      bitmap_ = new Bitmap();
    }
    ~BitmapTest() {
      delete bitmap_;
      bitmap_ = NULL;
    }
    Bitmap* bitmap_;
};

TEST_F(BitmapTest, size) {
  ASSERT_EQ(bitmap_->Size(), (size_t)0);
  bitmap_->Resize(2);
  ASSERT_GE(bitmap_->Size(), (size_t)2);
  ASSERT_EQ(bitmap_->Data_size(), (size_t)1);
  bitmap_->Resize(1000);
  ASSERT_EQ(bitmap_->Size() % 16, (size_t)0);
}

TEST_F(BitmapTest, bit) {
  bitmap_->Resize(1000);
  ASSERT_FALSE(bitmap_->TestBit(100));
  bitmap_->SetBit(100);
  ASSERT_TRUE(bitmap_->TestBit(100));
  bitmap_->ClearBit(100);
  ASSERT_FALSE(bitmap_->TestBit(100));
  bitmap_->SetBit(bitmap_->Size());
  ASSERT_FALSE(bitmap_->TestBit(bitmap_->Size()));
}

int main(int argc, char** argv) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
